package com.itany.corejava.code07_面向对象;

/**
 * @author MissChen
 * @version 1.0
 * @date 2023 年11月01日 14:06
 */
public class Test12_构造方法 {
    public static void main(String[] args) {
        Animal animal=new Animal("大黄",2,"狗","玩球");
        System.out.println(animal.name+",年龄:"+animal.age+",种类:"+animal.kind+",喜欢:"+animal.hobby);

    }
}
/*
* 定义一个动物类
*       属性:名字、年龄、种类、喜好
*       并定义相应的构造方法
*
* */

class Animal{
    String name;
    int age;
    String kind;
    String hobby;
    public Animal(){
        System.out.println("无参数的构造方法");
    }
    public Animal(String name){
        this.name=name;
    }
    public Animal(String name,int age){
        this(name);
        this.age=age;
    }
    public Animal(String name,int age,String kind){
        this.name=name;
        this.age=age;
        this.kind=kind;
    }
    public Animal(String name,int age,String kind,String hobby){
        this(name,age,kind);
        this.hobby=hobby;
    }
}
